package com.guowei.jiecloudbackstage.order.controller;


import com.alibaba.fastjson.JSONObject;
import com.guowei.jiecloudbackstage.order.entity.Atv;
import com.guowei.jiecloudbackstage.order.service.AtvService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ym
 * @since 2021-04-15
 */
@RestController
@Api(tags = "Order订单 接口")
@RequestMapping("/order")
public class AtvController {

    @Autowired
    private AtvService iOrderService;

    //    // 解决跨域问题
//    @CrossOrigin(origins ="*",maxAge = 3600)
    @RequestMapping("/getAll")
    @ResponseBody
    public Object getAll(HttpServletRequest request) {
        Map orderMap = new HashMap();

//        // 当前页数
//        int page = Integer.parseInt(request.getParameter("page"));
//        // 显示条数
//        int limit = Integer.parseInt(request.getParameter("limit"));
//        //作为sql语句的限制条件
//        int start = limit * (page-1);
//        // 查询出数据的总条数
//        int counts = iOrderService.orderCounts();
//        System.out.println(counts);

        String id = request.getParameter("orderId");
        if (id==null || id==""){
            List<Atv> orders = iOrderService.getAll();
            orderMap.put("code",0);
            orderMap.put("msg","lay ui-Table数据绑定数据库");
//            orderMap.put("count",counts);
            orderMap.put("data",orders);
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(orderMap));
            return jsonObject;
        }else{
            Atv order = new Atv();
            order.setOrderId(id);
            List<Atv> orders1 = iOrderService.getOrderById(order);
            orderMap.put("code",0);
            orderMap.put("msg","lay ui-Table数据绑定数据库");
//            orderMap.put("count",orders1.size());
            orderMap.put("data",orders1);
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(orderMap));
            return jsonObject;
        }
    }

    //根据id来查询房间订单的详细信息
//    public Object getOrderById(HttpServletRequest request){
//        try {
//
//            String na = request.getParameter("orderId");
//            System.out.println("id是"+na);
//            Integer id = Integer.parseInt(request.getParameter("orderId"));
//            if (0==id || "".equals(id)|| null==id){
//                List<Order> orders = iOrderService.getAll();
//                orderMap.put("code",200);
//                orderMap.put("msg","数据绑定数据库");
//                orderMap.put("data",orders);
//                JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(orderMap));
//                return jsonObject;
//            }else{
//                Map orderMap = new HashMap();
//
//                order.setOrderId(id);
//                List<Order> orders = iOrderService.getOrderById(order);
//                orderMap.put("code",200);
//                orderMap.put("msg","数据绑定数据库");
//                orderMap.put("data",orders);
//                JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(orderMap));
//                return jsonObject;
//            }
////            Result result = Result.ok(order1);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Result.error("根据id获取失败");
//        }
//    }

}
